<?php
require_once 'Excel/reader.php';
require_once 'ClsSebent//config.php';



class Content_class
{
	
		function get_data($table,$id,$field)
		{
			$q=" select * from `".$table."` where `id`='".$id."' ";
			$r=mysql_query($q);
			$l=mysql_fetch_array($r,MYSQL_ASSOC);
			$v=$l[$field];
			return ucfirst($v);
		}
		
		function showPageOption($link_page)
		{
			$sql="SELECT * FROM `site_page` WHERE `site_id`='".$_SESSION['SITE_ID']."' ORDER BY page_title";
			$result = mysql_query($sql);
			while($data=mysql_fetch_array($result))
			{
				if($link_page == $data["id"]) $set="selected";
				else $set="";				
							
				$style=($data["admin_pg"]=='Y')?'style="background-color:#FFFFCC"':'';
							
				echo "<option value=" . $data['id'] . " $set $style>" . stripslashes($data["page_title"])."</option>";
				
			}
			
		}

	function __construct()//DEFAULT CONSTRUCTOR
	{
	}
	
	function __destruct()//DEFAULT CONSTRUCTOR
	{
	}
	
//**********************************	

//CLASS FUNCTIONS.
	function Add_Product()
	{//echo 'add_product';
		//check session for admin.
					$this->Message="Product Added Successfully.";
		$act_conn=OpenConnection(); 
		if(isset($_SESSION['USERTYPE']) && ($_SESSION['USERTYPE']!='') && ($_SESSION['SITE_ID']!=''))
		{		
			$this->site_id=$_SESSION['SITE_ID'];
		//ADD PRODUCT TO PRODUCT MASTER.
			$Sql_query="INSERT INTO PRODUCT_MASTER(
			Owner_ID,
			product_title, 
			product_category, 
			product_desc,". 
			//product_img, 
			"product_img_alt, 
			product_price, 
			size, 
			color
			) VALUES(".
			$this->site_id.",'".
			mysql_escape_string($this->Product_title)."',".
			$this->Product_cat.",'".
			mysql_escape_string($this->Product_desc)."','".
//			mysql_escape_string($this->Product_imgurl)."','".
			mysql_escape_string($this->Product_imgalt)."',".
			$this->Product_price.",'".
			mysql_escape_string($this->Product_size)."','".
			mysql_escape_string($this->Product_color)
			."')";
			//echo $Sql_query;
			BeginTrans($act_conn);
			$res=mysql_query($Sql_query);
			$this->Product_id=mysql_insert_id($act_conn); echo $this->Product_id;
			if(! $res)
			{//echo'catch';
				RollBackTrans($act_conn);
				$this->Message="Product Master Failed.";
				CloseConnection($act_conn);
				return;
			}
			CommitTrans($act_conn);//echo'commit 1';
			
			//Upload Image file.
			$Sql_query="UPDATE PRODUCT_MASTER SET PRODUCT_IMG='Product_images/img_prod_".$this->Product_id.".jpg' WHERE product_id=".$this->Product_id;
			//echo $Sql_query;
//			BeginTrans($act_conn);
			$res=mysql_query($Sql_query);
			if(! $res)
			{//echo'catch';
				Product_RollBack();
				$this->Message="Product Master Image Failed.";
				CloseConnection($act_conn);
				return;
			}
//			CommitTrans($act_conn);//echo 'commit2';
			$this->Product_imgurl='Product_images/img_prod_'.$this->Product_id.'.jpg';			
			if($this-> Product_imgurl !="")
			{
				$this->Upload_ProductImage($this->Product_imgurl, $this->Product_id);
			}			
			
			//CALCULATE FINAL PRICE.
			$tax=$this->Product_price*($this->Tax_amt/100);
			$profit=$this->Product_price*($this->Profit_amt/100);
			$this->Product_finalprice=$this->Product_price+$tax+$profit;
		//ADD PRODUCT TO THE OWNER SITE.
			$Sql_query="INSERT INTO SITE_PRODUCT(
			site_id,
			product_id,
			product_title,
			profit_pct,
			profit_chk,".
			//price,
			"tax_pct,
			tax_chk,
			shipping_amt,
			final_price)VALUES(".	
			 $this->Site_id.",".
			 $this->Product_id.",'".
			 mysql_escape_string($this->Product_title)."',".			 
			 $this->Profit_amt.",'".
			 $this->Profit_on."',".			
			// $this->Product_price.",".
			 $this->Tax_amt.",'".
			 $this->Tax_on."',".						
			 $this->Shipping_amt.",".
			 $this->Product_finalprice
			.")";
			//echo $Sql_query;
			
//			BeginTrans($act_conn);
   		    $res=mysql_query($Sql_query);			
			//exit;
			//echo"site product success";			
			if(! $res)
			{
				Product_RollBack();
				$this->Message="Site Product Master Failed.";
				CloseConnection($act_conn);
				return;
			}
			//CommitTrans($act_conn);//echo'commit3';
			$Site_Product_id=mysql_insert_id();
			CloseConnection($act_conn);
			//UPLOAD ADDON LIST AND PRICE LOT LIST.
			if($this->addonFileName !="")
			{
				$this->Upload_Addons($this->addonFileName, $this->Product_id);
			}
//			echo"addons success";
			
			if($this-> lotpriceFileName !="")
			{
				$this->Upload_LotPricingList($this->lotpriceFileName, $this->Product_id);
			}
//			echo"Lots success";
			
//			CENTRAL UPDATE.
			$this->Notify_Product_Update();

			//CommitTrans($act_conn);			
		}
		else
		{
			$this->Message="Sorry, Product could not be added. Please try again.";
			CloseConnection($act_conn);
		}
		return;
		
	}	
	
	function Check_ProductOwner()
	{
			echo 'Check_ProductOwner';
			if($_SESSION['USERTYPE']!='ADMIN')
			{
				$Sql_query="SELECT Owner_ID FROM PRODUCT_MASTER WHERE Owner_ID=".$_SESSION['SITE_ID']." AND product_id=".$this->Product_id;
//				echo $Sql_query;
				$act_conn=OpenConnection();
				$res=mysql_query($Sql_query);
				if(!$res)
				{
					$this->Message="Sorry you dont have rights to change a Product.";			
					CloseConnection();					
					return false;
				}
				$result=mysql_fetch_array($res);
				if($result["Owner_ID"]=="")
				{
					$this->Message="Sorry you dont have rights to change a Product.";			
					CloseConnection($act_conn);					
					return false;
				}
				CloseConnection($act_conn);
			}
			
			return true;
	}
	
	
	function Update_Product()
	{	//echo'Update_Product';
	// Master Updation.	
	OpenConnection($act_conn);
	BeginTrans($act_conn);
	
		if($this->Update_Product_Master($act_conn))
		{	
			if($this->Notify_Product_Update())
			{			
				$this->Message="Product Updated Sucessfully.";
				CommitTrans($act_conn);
				CloseConnection($act_conn);						
			}
			else
			{
				RollBackTrans($act_conn);
				CloseConnection($act_conn);			
			}
		}
		else
		{
			RollBackTrans($act_conn);
			CloseConnection($act_conn);
		}
		return;
	}
	
	function Update_Product_Master()
	{ //echo'Update_Product_Master';
		$Sql_qry="UPDATE PRODUCT_MASTER SET ".
		//"Owner_ID=".$this->site_id.",".
		"product_title='".mysql_escape_string($this->Product_title)."', ".
		"product_category=".$this->Product_cat.", ".
		"product_desc='".mysql_escape_string($this->Product_desc)."', ".
		"product_img_alt='".mysql_escape_string($this->Product_imgalt)."', ".
		"product_price=".$this->Product_price.", ".
		"size='".mysql_escape_string($this->Product_size)."', ".
		"color='".mysql_escape_string($this->Product_color)."'"
		;		

		$rs=mysql_query($Sql_qry);
		//echo $Sql_qry;
		if(! $rs)
		{
			RollBackTrans($act_conn);
			$this->Message="Update Product Master Failed.";
			CloseConnection($act_conn);
			return false;
		}
			$product_image=	'Product_images/img_prod_'.$this->Product_id.'.jpg';
			$Sql_query="UPDATE PRODUCT_MASTER SET PRODUCT_IMG='".mysql_escape_string($product_image)."' WHERE product_id=".$this->Product_id;
			//echo $Sql_query;
			$res=mysql_query($Sql_query);
			if(! $res)
			{
				RollBackTrans($act_conn);
				$this->Message="Product Update Image Failed.";
				CloseConnection($act_conn);
				return false;
			}
			
		if($this->Product_imgurl!="")
		{			
			$this->Upload_ProductImage($this->Product_imgurl, $this->Product_id);			
		}
		$this->Product_imgurl='Product_images/img_prod_'.$this->Product_id.'.jpg';
		if($this->addonFileName!="")
		{	
			$this->DeleteExistingAddons();
			$this->Upload_Addons($this->addonFileName, $this->Product_id);
		}
		if($this->lotpriceFileName)
		{
			$this->DeleteExistingPricing();
			$this->Upload_LotPricingList($this->lotpriceFileName, $this->Product_id);	
		}
		return;
	}
	
	function Notify_Product_Update()
	{//echo'Notify_Product_Update';
		$Sql_query="INSERT INTO UPDATESTABLE(
			Site_ID,
			Updation_date,
			Updated_Table,
			Updated_RecID,
			Updated_Cols,
			Updation_Type) VALUES(".
			$this->Site_id.",'".
			date('m/d/Y')."',".
			"'PRODUCT_MASTER',".
			$this->Product_id.",'".
			"ALL','".
			"P')";
			
			//echo $Sql_query;
			$act_conn=OpenConnection(); 
			//BeginTrans($act_conn);
			//$res=mysql_query($Sql_query)or die(mysql_error());
			if(!($res=mysql_query($Sql_query)or die(mysql_error())))
			{  
				Product_RollBack();
				$Message="Product Updates Notification Failed.";
				CloseConnection($act_conn);
				return;
			}
			//CommitTrans($act_conn);
			CloseConnection($act_conn);
			return;		
	}
	
	function Update_ProductSettings()
	{//echo 'Update_ProductSettings';
		$act_conn=OpenConnection();
		$tax=$this->Product_price*($this->Tax_amt/100);
		$profit=$this->Product_price*($this->Profit_amt/100);
		$this->Product_finalprice=$this->Product_price+$tax+$profit;
		$Sql_query="UPDATE SITE_PRODUCT SET 
		profit_pct=".$this->Profit_amt.
		", profit_chk='".$this->Profit_on."'".
		", tax_pct=".$this->Tax_amt.
		", tax_chk='".$this->Tax_on."'".
		", final_price=".$this->Product_finalprice.
		" WHERE product_id=".$this->Product_id." AND site_id=".$this->Site_id;
//		echo $Sql_query;
		BeginTrans($act_conn);
		$res=mysql_query($Sql_query);		
		if(!$res)
		{
			$this->Message="Update Product Settings Failed.";
			RollBackTrans($act_conn);
			CloseConnection($act_conn);
			return;
		}
		
		$this->Message="Updated Product Settings Successfully.";
		CommitTrans($act_conn);
		CloseConnection($act_conn);
		return;
	}
	
	function Delete_Product()
	{//echo'Update_ProductSettings';
		$act_conn=OpenConnection();
		if($_SESSION['USERTYPE']!='ADMIN')
		{
			$Sql_query="SELECT Owner_ID FROM PRODUCT_MASTER WHERE Owner_ID=".$_SESSION['SITE_ID']."AND product_id=".$this->Product_id;
			$res=mysql_query($Sql_query);
			if(! $res)
			{
				$this->Message="Sorry you dont have rights to delete this Product.";			
				CloseConnection($act_conn);					
				return;
			}			
			/*$result=mysql_fetch_row($res);
			if($result[0]=="")
			{
				$this->Message="Sorry you dont have rights to delete a Product.";			
				CloseConnection();					
				exit;
			}*/ //NOT NEEDED. MAY BE OF FURTHER USE.
		
			$Sql_query="DELETE FROM PRODUCT_MASTER WHERE product_id=".$this->Product_id;				
			BeginTrans($act_conn);
			$rs=mysql_query($Sql_query);
			if(!$rs)
			{
				RollbackTrans($act_conn);
				$this->Message="Delete Master Product Failed. Please Try Again.";
				CloseConnection($act_conn);
				return;
			}
			//NOW DELETE ADDONS.
			$this->DeleteExistingAddons();
			
			//NOW DELETE LOT PRICING.
			$this->DeleteExistingPricing();		
			
			$this->Message="Master Product Deleted Successfully.";
			CommitTrans($act_conn);
			CloseConnection($act_conn);
		}
			return;
	}	
	
	function Delete_SiteProduct()
	{
		$act_conn=OpenConnection();
		BeginTrans($act_conn);
		$Sql_query="DELETE FROM SITE_PRODUCT WHERE product_id=".$this->Product_id." AND site_id=".$this->Site_id;
		$res=mysql_query($Sql_query);
		if(!$res)
		{
			RollBackTrans($act_conn);
			$this->Message="Delete Local Product Failed. Please Try Again.";
			CloseConnection($act_conn);
			exit;
		}		
		$this->Message="Local Product Deleted Successfully.";
		CommitTrans($act_conn);
		CloseConnection($act_conn);		
		return;
	}
	
	function Select_Product()
	{	
		$Sql_query="SELECT * FROM SITE_PRODUCT LEFT JOIN PRODUCT_MASTER ON SITE_PRODUCT.product_id= PRODUCT_MASTER.product_id AND SITE_PRODUCT.product_id=".$this->Product_id;
		$act_conn=OpenConnection();
		$res=mysql_query($Sql_query);
			if(! $res)
			{				
				$Message="Product Selection Failed.";
				CloseConnection($act_conn);
				return;
			}
		$result=mysql_fetch_array($res);
		if(! $result)
			{				
				$Message="Product Selection_rec Failed.";
				CloseConnection($act_conn);
				return;
			}//echo $result["product_title"];
//		return $result;
		$this->Product_title=$result["product_title"];
		$this->Product_cat=$result["product_category"];
		$this->Product_desc=$result["product_desc"];
		$this->Product_imgurl=$result["product_img"];
		$this->Product_imgalt=$result["product_img_alt"];
		$this->Product_price=$result["product_price"];
		$this->Product_size=$result["size"];
		$this->Product_color=$result["color"];
		$this->site_id=$result["site_id"];
		$this->Profit_amt=$result["profit_pct"];
		$this->Profit_on=$result["profit_chk"];
		$this->Tax_amt=$result["tax_pct"];
		$this->Tax_on=$result["tax_chk"];
		$this->Shipping_amt=$result["shipping_amt"];
		$this->Product_finalprice=$result["final_price"];		
		$this->Message="Selected Product Details.";
		CloseConnection($act_conn);		
		return;					
	}
	
	function List_Products()
	{
		$act_conn=OpenConnection();
		$Sql_query="SELECT * FROM SITE_PRODUCT LEFT JOIN PRODUCT_MASTER ON SITE_PRODUCT.product_id= PRODUCT_MASTER.product_id ORDER BY PRODUCT_MASTER.".$this->Product_Listorder;
//echo $Sql_query;

		$rs=mysql_query($Sql_query);
		if(! $rs)
		{
			$this->Message="Product Listing Failed.";
			CloseConnection($act_conn);
			return;
		}
		//RENDER DATA ROWS WITH CONTROLS TO UI.
		
		while($result=mysql_fetch_array($rs,MYSQL_ASSOC))
		{
			echo'<tr>';
			echo'<td><input type="image" name="img_edit_product" value="'.$result["product_id"].'" src="images/edit.jpg" alt="Edit Product" width="25" height="25"></td>';
			//echo'<td width="3%"><input type="image" name="img_edit_local" value="'.$result["product_id"].'" src="images/edit1.jpg" alt="Edit Local Settings" width="25" height="25"></td>';
			echo'<td><input type="image" name="img_del_master" value="'.$result["product_id"].'" src="images/delete.jpg" alt="Delete Master Product" width="25" height="25"></td>';
			echo'<td width="3%"><input type="image" name="img_del_local" value="'.$result["product_id"].'" src="images/delete1.jpg" alt="Delete Local Product" width="25" height="25"/></td>';
			echo'<td>'.$result["product_title"].'</td>';
			$this->Product_cat=$result["product_category"];
			$Product_category=$this->Select_Category();
			echo'<td>'.$Product_category.'</td>';			
			echo'<td>'.$result["product_price"].'</td>';
			echo'<td>'.$result["profit_pct"].'</td>';
			echo'<td>';
			if($result["profit_chk"]=='Y') echo"<img src='images/tick.jpg' alt='Profit Applied' width='25' height='25'/>"; else echo"<b>x</b>"; echo'</td>';
			if($result["profit_chk"]=='Y')
			$sel_price=$result["product_price"]+ ($result["product_price"]*($result["profit_pct"]/100));
			else
			$sel_price=$result["product_price"];
			echo'<td>'.$sel_price.'</td>';			
			echo'<td>'.$result["tax_pct"].'</td>';
			echo'<td>';	if($result["tax_chk"]=='Y') echo"<img src='images/tick.jpg' alt='Tax Applied' width='25' height='25'/>"; else echo"<b>x</b>"; echo'</td>';
			$Tax=$result["product_price"]+($result["product_price"]*($result["tax_pct"]/100));		//STILL UNUSED..MAY BE USED LATER.
			echo'<td>'.$result["shipping_amt"].'</td>';
			echo'<td>'.$result["final_price"].'</td>';
			echo'</tr>';
		}
				CloseConnection($act_conn);
				return;
	}
	
	function Add_Category()
	{
		$qry="SELECT category_name FROM PRODUCT_CATEGORY WHERE category_name='".mysql_escape_string($this->Product_category)."'";
		//echo $qry;
		$act_conn=OpenConnection();
		$rs=mysql_query($qry);
		if(! $rs)
		{
			$this->Message="Category Varification Failed.";
			CloseConnection($act_conn);
			return;
		}
		$result=mysql_fetch_row($rs);
		if($result[0]=="")
		{
		$qry="INSERT INTO PRODUCT_CATEGORY(Category_name) VALUES('".mysql_escape_string($this->Product_category)."')";
		//echo $qry;
		mysql_query($qry);
		$this->Message="Category Added Successfully.";				
		CloseConnection($act_conn);	
		return;
		}
		else 
		{
			$this->Message="Category Additon Failed. Please Try Again.";
			CloseConnection($act_conn);
			return;		
		}
	}
	
	function Load_categories()
	{//echo "load category";
		$qry="SELECT * FROM PRODUCT_CATEGORY";
		$act_conn=OpenConnection();
		$rs=mysql_query($qry);
		if(! $rs)
		{
			$this->Message="Categories Load Failed.";
			CloseConnection($act_conn);
			return;		
		}
		while($result=mysql_fetch_array($rs))
		{
			echo '<option value="'.$result["Category_ID"].'">'.$result["Category_name"].'</option>';
		}
		CloseConnection($act_conn);
		return;
	}
	
	function Select_Category()
	{
		//OpenConnection(); FUNCTION RUNS UNDER AN ALREADY OPEN CONNECTION.
		$Sql_query="SELECT Category_name FROM PRODUCT_CATEGORY WHERE Category_id=".$this->Product_cat;
		$res=mysql_query($Sql_query);
		if(!$res)
		{
			//CloseConnection();
			return "";
		}
		$result=mysql_fetch_array($res);
		
		//CloseConnection();
		return $result["Category_name"];
	}
	
	function Upload_Addons($addonFileName, $product_id)
	{
		//echo $addonFileName;		
		$act_conn=OpenConnection();
		$data = new Spreadsheet_Excel_Reader();
		$data->setOutputEncoding('CP1251');
		$data->setUTFEncoder('mb');
		$data->read($addonFileName);
		error_reporting(E_ALL ^ E_NOTICE);		
		BeginTrans($act_conn);
				for ($i = 1; $i <= $data->sheets[0]['numRows']-1; $i++)
				{						//echo "<br>";
					//var $qry1=$qry.$data->sheets[0]['cells'][$i][1].",'".$data->sheets[0]['cells'][$i][2]."','".$data->sheets[0]['cells'][$i][3]."',".$data->sheets[0]['cells'][$i][4].")";
					if($i>1)//VALUES FROM ROW 2 ONWARDS.
					{
						for ($j = 3; $j <= $data->sheets[0]['numCols']; $j++) 
						{	
							//leave column 2 every time.
							$addon_color=$data->sheets[0]['cells'][$i][1];
							$addon_size=$data->sheets[0]['cells'][1][$j];
							$addon_price=str_replace("$","", $data->sheets[0]['cells'][$i][$j]);
								//echo "color: ".$data->sheets[0]['cells'][$i][1]." Size: ".$data->sheets[0]['cells'][1][$j]." cost: ".str_replace("$","", $data->sheets[0]['cells'][$i][$j])." -- ";
							$qry="INSERT INTO PRODUCT_ADDON(product_id, addon_title, addon_color, addon_size, addon_price) VALUES(".
							$product_id.",'".
							mysql_escape_string($addon_color)."-".mysql_escape_string($addon_size)."','". //Whilte-xxxl
							mysql_escape_string($addon_color)."','".
							mysql_escape_string($addon_size)."',".							
							mysql_escape_string($addon_price)
							.")";
							
							//echo $qry."<br>";		
							$res=mysql_query($qry) or die(mysql_error());
							if(! $res)
							{ //echo 'Addon Rollback';
					//			RollBackTrans($act_conn);
								$this->Product_RollBack();
								$this->Message="Product Addons Failed.";
								CloseConnection($act_conn);
								return;
							}
						}
					}					
				}//FOR
				//CommitTrans($act_conn);
				CloseConnection($act_conn);	
				return;
	}
	
	function Upload_LotPricingList($lotpriceFileName, $product_id)
	{
		//$addonFileName=$_FILES['myfile']['tmp_name'];
		//echo $addonFileName;
		//$product_id=1;//to be passed in the function.
		$data = new Spreadsheet_Excel_Reader();
		$data->setOutputEncoding('CP1251');
		$data->setUTFEncoder('mb');
		$data->read($lotpriceFileName);
		error_reporting(E_ALL ^ E_NOTICE);	
		
		$act_conn=OpenConnection();
	//	BeginTrans($act_conn);	
				
				for ($i = 5; $i <= $data->sheets[0]['numRows']-1; $i++)
				{						//echo "<br>";
//				echo "I ".$i; echo " cellvalue ".$data->sheets[0]['cells'][$i][1]."<br>";					
						if(($data->sheets[0]['cells'][$i][1]!="") && ($data->sheets[0]['cells'][$i][2]!="") && ($data->sheets[0]['cells'][$i][3]!=""))
						{ //echo "Hi";
								for ($j = 2; $j <= $data->sheets[0]['numCols']; $j++) 
								{	
									//leave column 2 every time.
									$lot_size_m=$lot_size_h=0;
										$lot_limits=explode("-",$data->sheets[0]['cells'][$i][1]);
										$lot_size_m=str_replace("+","",$lot_limits[0]);
										if($lot_limits[1]!=0)
										{
											$lot_size_h=$lot_limits[1];
										}
									
										$no_of_colors=$data->sheets[0]['cells'][3][$j];
										$no_of_colors=str_replace("(","",$no_of_colors);
										$no_of_colors=str_replace(")","",$no_of_colors);
										$lot_price=$data->sheets[0]['cells'][$i][$j];
									
									
									//echo "color: ".$data->sheets[0]['cells'][$i][1]." Size: ".$data->sheets[0]['cells'][1][$j]." cost: ".str_replace("$","", $data->sheets[0]['cells'][$i][$j])." -- ";
									$qry="INSERT INTO PRODUCT_LOT_PRICING(product_id, lot_size_m, lot_size_h, no_of_colors, lot_price) VALUES(".
									$product_id.",".
									$lot_size_m.",".
									$lot_size_h.",".
									$no_of_colors.",".							
									$lot_price
									.")";
									
									//echo $qry."<br>";		
									$res=mysql_query($qry) or die(mysql_error());
									if(! $res)
									{echo 'Pricing Rollback';
										//RollBackTrans($act_conn);
										$this->Product_RollBack();
										$this->Message="Product Lot Pricing Failed.";
										CloseConnection($act_conn);
										return;
									} 
								}//END FOR
						}//END IF									
				
				}//END FOR
				//CommitTrans($act_conn);
				CloseConnection($act_conn);
				return;
	}
	
	function Upload_ProductImage($Product_imgurl, $Product_id)
	{
		if(is_uploaded_file($Product_imgurl))
				{
				//echo $Product_imgurl;
					move_uploaded_file($Product_imgurl,"Product_images/img_prod_".$Product_id.".jpg");
				}			
				return;
	}
	
	function DeleteExistingAddons()
	{
			$act_conn=OpenConnection();
			BeginTrans($act_conn);
			$Sql_query="DELETE FROM PRODUCT_ADDONS WHERE product_id=".$this->Product_id;
			$res=mysql_query($Sql_query);
			if(! $res)
			{
				$this->RollbackTrans($act_conn);
				$this->Message="Delete Product Addons Failed. Please Try Again.";
				CloseConnection($act_conn);
				return;
			}
			CommitTrans($act_conn);
			CloseConnection($act_conn);
			return;
	}
	
	function DeleteExistingPricing()
	{
		$Sql_query="DELETE FROM PRODUCT_LOT_PRICING WHERE product_id=".$this->Product_id;
		$act_conn=OpenConnection();
		BeginTrans($act_conn);
			$res=mysql_query($Sql_query);
			if(! $res)
			{
				$this->RollbackTrans($act_conn);
				$this->Message="Delete Product Lot Pricing Failed. Please Try Again.";
				CloseConnection($act_conn);
				return;
			}
		CommitTrans($act_conn);
		CloseConnection($act_conn);
		return;
	}
	
	function Product_RollBack()
	{
//	echo'ROLLBACK';
		$act_conn=OpenConnection();		
		$Sql_query="DELETE FROM PRODUCT_MASTER WHERE PRODUCT_ID=".$this->Product_id; //echo'1';
		mysql_query($Sql_query,$act_conn) or die(mysql_error());
		$Sql_query="DELETE FROM SITE_PRODUCT WHERE PRODUCT_ID=".$this->Product_id." AND SITE_ID=".$this->Site_id; //echo $Sql_query;
		mysql_query($Sql_query, $act_conn) or die(mysql_error());		
		$Sql_query="DELETE FROM PRODUCT_ADDON WHERE PRODUCT_ID=".$this->Product_id;
		mysql_query($Sql_query, $act_conn) or die(mysql_error());
		$Sql_query="DELETE FROM PRODUCT_LOT_PRICING WHERE PRODUCT_ID=".$this->Product_id;
		mysql_query($Sql_query,$act_conn) or die(mysql_error());
		$this->Message="Product Can't Be Added.";
		CloseConnection($act_conn);
		return;
	}
}
?>